/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div>
      <div class="fixed-bar">
        <div class="item-title">
          <router-link class="back" :to="{name:'members'}" title="返回列表">
            <i class="fa fa-arrow-circle-o-left"></i>
          </router-link>
          <div class="subject">
            <h3>会员管理 - 添加会员</h3>
            <h5>网站系统添加会员</h5>
          </div>
        </div>
      </div>
      <form :model="form" class="form-horizontal">
        <div class="ncap-form-default">
          <dl class="row">
            <dt class="tit">
              <label>
                <em>*</em>会员昵称
              </label>
            </dt>
            <dd class="opt">
              <input v-model="form.nickname" type="text" class="input-txt" />
              <p class="err-msg" v-if="errResult.nickname && !form.nickname">{{errResult.nickname}}</p>
            </dd>
          </dl>
          <dl class="row">
            <dt class="tit">
              <label>
                <em>*</em>登录密码
              </label>
            </dt>
            <dd class="opt">
              <input v-model="password" type="password" class="input-txt" />
              <p
                class="err-msg"
                v-if="errResult.password && (!form.password || form.password.length < 6 || form.password.length > 16)"
              >{{errResult.password}}</p>
              <p class="notic">6-16位字母数字符号组合</p>
            </dd>
          </dl>
          <dl class="row">
            <dt class="tit">
              <label>
                <em>*</em>手机号码
              </label>
            </dt>
            <dd class="opt">
              <input
                v-model="form.mobile"
                type="text"
                onpaste="this.value=this.value.replace(/[^\d.]/g,'')"
                onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"
                class="input-txt"
              />
              <p class="err-msg" v-if="errResult.mobile && !form.mobile">{{errResult.mobile}}</p>
              <p class="notic">前台登陆账号，手机邮箱任意一项都可以</p>
            </dd>
          </dl>
          <dl class="row">
            <dt class="tit">
              <label>
                <em>*</em>邮件地址
              </label>
            </dt>
            <dd class="opt">
              <input v-model="form.email" type="text" class="input-txt" />
              <p class="err-msg" v-if="errResult.email && !form.email">{{errResult.email}}</p>
              <p class="notic">前台登陆账号，手机邮箱任意一项都可以</p>
            </dd>
          </dl>
          <dl class="row">
            <dt class="tit">
              <label>QQ</label>
            </dt>
            <dd class="opt">
              <input
                v-model="form.qq"
                type="text"
                onpaste="this.value=this.value.replace(/[^\d.]/g,'')"
                onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"
                class="input-txt"
              />
            </dd>
          </dl>
          <dl class="row">
            <dt class="tit">
              <label>性别</label>
            </dt>
            <dd class="opt">
            <template>
                <el-radio-group v-model="form.sex">
                  <el-radio :label="0">保密</el-radio>
                  <el-radio :label="1">男</el-radio>
                  <el-radio :label="2">女</el-radio>
                </el-radio-group>
              </template>
            </dd>
          </dl>
          <div class="bot">
            <el-button type="primary" @click="onSubmit()" :loading="isLoading">确认提交</el-button>
          </div>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
import { addUser } from "@/utils/api";
import md5 from "@/utils/md5.js";
export default {
  data() {
    return {
      id: null,
      form: {
        sex: 0
      },
	  password: "",
      isLoading: false,
      errResult: { mobile: null }
    };
  },
  created() {},
  methods: {
    onSubmit() {
      //手机或邮箱校验
      if (!this.form.mobile && !this.form.email) {
        this.$message.error("参数错误");
        this.errResult.mobile = "手机和邮箱至少填一项";
        return;
      }
      this.isLoading = true;
      var that = this;
	  that.form.password =  md5("TPSHOP" + that.password)
      addUser(that.form).then(function(res) {
        if (res.status == 1) {
          that.$message.success({
            message: "添加成功",
            duration: 1000,
            onClose: function() {
              that.$router.push({
                name: "members"
              });
            }
          });
        } else if (res.status == -1) {
          that.$message.error("参数错误");
          that.errResult = res.result;
        } else {
          that.$message.error(res.msg);
        }
        that.isLoading = false;
      });
    }
  }
};
</script>

<style scoped>
</style>
